package com.turing.post.organization.impl;

import java.util.List;

import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import com.turing.post.organization.util.MerchantBusinessType;
import com.turing.post.organization.util.MerchantBusinessTypeDao;
import com.turing.post.util.GeneralDao;
import com.turing.post.util.PCPSApplicationException;

@Stateless(mappedName = "organization.impl.MerchantBusinessTypeDaoImpl")
@Remote
@Local
public class MerchantBusinessTypeDaoImpl implements MerchantBusinessTypeDao {

	/**
	 * 实体管理器
	 */
	@PersistenceContext
	protected EntityManager _em;

	@SuppressWarnings("unchecked")
	@Override
	public List<MerchantBusinessType> getAllMerchantBusinessTypeByMerchantNo(
			String merchantNo) {
		String sql = "select t.* from MerchantBusinessType t where t.MerchantNo = ?1";
		Query query = _em.createNativeQuery(sql, MerchantBusinessType.class);
		query.setParameter(1, merchantNo);
		return query.getResultList();
	}

	@Override
	public MerchantBusinessType getMerchantBusinessTypeByKey(
			MerchantBusinessType mbt) {
		return _em.find(MerchantBusinessType.class, mbt);
	}

	@Override
	public void insert(MerchantBusinessType mbt)
			throws PCPSApplicationException {
		GeneralDao.update(_em, mbt);
	}

	@Override
	public void update(MerchantBusinessType mbt)
			throws PCPSApplicationException {
		GeneralDao.insert(_em, mbt);
	}

	@Override
	public void delete(MerchantBusinessType mbt)
			throws PCPSApplicationException {
		GeneralDao.remove(_em, mbt);
	}
}
